package com.ygo.feihua.adapter;

import android.content.*;
import android.graphics.*;
import android.view.*;
import android.widget.*;
import com.qnw.CardGroupManagement.management.*;
import com.ygo.feihua.*;
import java.util.*;

public class AdapterCardImage extends BaseAdapter
{

	private List<String> data;
	private List<String> xzci;
	private Context context;

	private boolean selected=false;

	public AdapterCardImage(Context context ,List<String> data,List<String> xzci){
		this.context=context;
		this.data=data;
		this.xzci=xzci;
	}

	Zujian zujian;

	public void setSelected(boolean selected)
	{
		this.selected = selected;
		notifyDataSetChanged();
	}

	public boolean isSelected()
	{
		return selected;
	}

	class Zujian{
		RelativeLayout cdb_lin;
		TextView cdb_name;
		CheckBox cdb_ch;
	}

	@Override
	public int getCount()
	{
		// TODO: Implement this method
		return data.size();
	}

	@Override
	public Object getItem(int p1)
	{
		// TODO: Implement this method
		return data.get(p1);
	}

	@Override
	public long getItemId(int p1)
	{
		// TODO: Implement this method
		return p1;
	}

	@Override
	public View getView(int position, View p2, ViewGroup p3)
	{
		if(p2==null){
			zujian=new Zujian();
			p2=LayoutInflater.from(context).inflate(R.layout.item_cdb,null);
			zujian.cdb_name=(TextView) p2.findViewById(R.id.cdb_name);
			zujian.cdb_lin= (RelativeLayout) p2.findViewById(R.id.cdb_lin);
			zujian.cdb_ch=(CheckBox) p2.findViewById(R.id.cdb_ch);
			p2.setTag(zujian);

		}else{
			zujian=(Zujian) p2.getTag();
		}
		String path= data.get(position);
		
		zujian.cdb_name.setText(path);
		
		if(selected){
			if(position!=data.size()-1){
				zujian.cdb_ch.setVisibility(View.VISIBLE);

				if(xzci.contains(path)){
					zujian.cdb_ch.setChecked(true);
				}else{
					zujian.cdb_ch.setChecked(false);
				}
			}else{
				zujian.cdb_ch.setVisibility(View.GONE);
			}
		}else{
			xzci.clear();
			zujian.cdb_ch.setVisibility(View.GONE);
		}


		// TODO: Implement this method
		return p2;
	}



}
